package com.jackrain.nea.fc.dl.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;

/**
 * fc改单传到wms
 * Mapper
 *
 * @author kangcong
 * @create 2018/08/20
 */
@Mapper
public interface WMSDLUpdateMapper {


    @Select("SELECT AMT_OUT,SETTLEMENT_PRICE,SETTLEMENT_AMT FROM DL_B_TRAN_ITEM_SKU WHERE PS_C_SKU_ECODE=#{skuecode} AND DL_B_TRAN_ID=#{ids}")
    List<HashMap> selectItemByBillId(@Param("ids") Long ids, @Param("skuecode") String skuecode);


    @Select(" SELECT " +
            "ID, " +
            "BILL_NO, " +
            "BILL_DATE, " +
            "CP_C_SUPPLIER_ECODE AS ORIG_ECODE, " +
            "CP_C_STORE_ECODE AS DEST_ECODE, " +
            "REMARK, " +
            "OWNERENAME AS OWNER_ENAME, " +
            "OWNERNAME AS OWNER_NAME,  " +
            "CREATIONDATE AS CREATION_DATE, " +
            "MODIFIERENAME AS MODIFIER_ENAME, " +
            "MODIFIERNAME AS MODIFIER_NAME, " +
            "MODIFIEDDATE AS MODIFIED_DATE,  " +
            "MODIFY_BILL_NO," +
            "WMS_IN " +
            "FROM DL_B_PUR_IN  " +
            "WHERE MODIFY_BILL_NO IS NOT NULL AND ID IN (#{ids})")
    HashMap selectWmsPurIn(String ids);

    @Select("SELECT  " +
            "PS_C_SKU_ECODE AS SKU,  " +
            "QTY_BILL,  " +
            "OWNERENAME AS OWNER_ENAME,  " +
            "OWNERNAME AS OWNER_NAME,  " +
            "CREATIONDATE AS CREATION_DATE,  " +
            "MODIFIERENAME AS MODIFIER_ENAME,  " +
            "MODIFIERNAME AS MODIFIER_NAME,  " +
            "MODIFIEDDATE AS MODIFIED_DATE  " +
            "FROM DL_B_PUR_IN_ITEM  " +
            "WHERE DL_B_PUR_IN_ID IN ( #{ids} )")
    List<HashMap> selectWmsPurInItem(String ids);

    @Select("SELECT  " +
            "BILL_NO AS  bill_no, " +
            "DATE_FORMAT( BILL_DATE,'%Y-%m-%d' ) AS bill_date , " +
            "CP_C_STORE_ECODE AS orig_ecode , " +
            "CP_C_SUPPLIER_ECODE AS dest_ecode, " +
            "REMARK AS remark, " +
            "OWNERENAME AS owner_ename , " +
            "OWNERNAME AS owner_name, " +
            "CREATIONDATE AS creation_date , " +
            "MODIFIERENAME AS modifier_ename, " +
            "MODIFIERNAME AS modifier_name, " +
            "MODIFIEDDATE AS modified_date, " +
            "MODIFY_BILL_NO AS  userdefine1 " +
            "FROM DL_B_PUR_RET " +
            "WHERE ID = #{ids} " +
            "AND MODIFY_BILL_NO IS NOT NULL " +
            "AND STATUS = 2")
    HashMap selectWmsPurRet(Long ids);

    @Select("SELECT  " +
            "PS_C_SKU_ECODE AS sku , " +
            "QTY_BILL AS qty_bill, " +
            "OWNERENAME AS owner_ename, " +
            "OWNERNAME AS owner_name, " +
            "CREATIONDATE AS creation_date, " +
            "MODIFIERENAME AS modifier_ename, " +
            "MODIFIERNAME AS modifier_name, " +
            "MODIFIEDDATE AS modified_date   " +
            "FROM DL_B_PUR_RET_ITEM  " +
            "WHERE DL_B_PUR_RET_ID=#{ids}")
    List<HashMap> selectWmsPurRetItem(Long ids);

    @Select("SELECT  " +
            "TRAN_TYPE AS TRAN_TYPE, " +
            "FROM_BILL_ID AS FROM_BILL_ID, " +
            "ID AS ID " +
            "FROM DL_B_TRAN " +
            "WHERE  BILL_NO=#{billno}")
    HashMap select1(String billno);

    @Select("SELECT  " +
            "ID AS ID " +
            "FROM DL_B_TRAN " +
            "WHERE  FROM_BILL_NO=#{wmsbillno}")
    Long selectObjidByWmsBillNo(String wmsbillno);


    @Select("SELECT COUNT(1) FROM DL_B_INV_ADJ WHERE ISACTIVE='Y' AND WMS_BILL_NO =#{wms_bill_no}")
    int selectWmsCount(String wms_bill_no);

    @Select("SELECT DISTINCT STATUS FROM DL_B_INV_ADJ WHERE ISACTIVE='Y' AND WMS_BILL_NO =#{wms_bill_no}")
    int selectWmsStatus(String wms_bill_no);

    @Select("SELECT DISTINCT ACCEPTE_STATUS FROM DL_B_INV_ADJ WHERE ISACTIVE='Y' AND WMS_BILL_NO =#{wms_bill_no}")
    int selectWmsAccepteSta(String wms_bill_no);
}
